From a232df4e779faf0993867a26a00a58c94c6a4d9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sun, 14 Jan 2018 23:55:53 +0100 Subject: [PATCH] babl: store pointer to where user data resides instead of copy This will make the scenario of changing user data work, we do it unconditionally to avoid introducing a branch. --- babl/babl-fish-path.c | 11 +++++++---- babl/babl-fish.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c index 301dd5c..d384e1c 100644 --- a/babl/babl-fish-path.c +++ b/babl/babl-fish-path.c @@ -675,10 +675,12 @@ _babl_fish_rig_dispatch (Babl *babl) if (babl->fish.source == babl->fish.destination) { babl->fish.dispatch = babl_fish_memcpy_process; + babl->fish.data = (void*)&(babl->fish.data); } else { babl->fish.dispatch = babl_fish_reference_process; + babl->fish.data = (void*)&(babl->fish.data); } break; @@ -688,7 +690,7 @@ _babl_fish_rig_dispatch (Babl *babl) /* lift out conversion from single step conversion and make it be the dispatch function * itself */ - babl->fish.data = babl->fish_simple.conversion->data; + babl->fish.data = &babl->fish_simple.conversion->data; babl->fish.dispatch = babl->fish_simple.conversion->dispatch; } else @@ -705,11 +707,12 @@ _babl_fish_rig_dispatch (Babl *babl) /* do same short-circuit optimization as for simple fishes */ babl->fish.dispatch = conversion->dispatch; - babl->fish.data = conversion->data; + babl->fish.data = &conversion->data; } else { babl->fish.dispatch = babl_fish_path_process; + babl->fish.data = (void*)&(babl->fish.data); } break; @@ -735,7 +738,7 @@ _babl_process (const Babl *cbabl, Babl *babl = (void*)cbabl; babl->fish.processings++; babl->fish.pixels += n; - babl->fish.dispatch (babl, source, destination, n, babl->fish.data); + babl->fish.dispatch (babl, source, destination, n, *babl->fish.data); return n; } @@ -771,7 +774,7 @@ babl_process_rows (const Babl *fish, babl->fish.pixels += n * rows; for (row = 0; row < rows; row++) { - babl->fish.dispatch (babl, (void*)src, (void*)dst, n, babl->fish.data); + babl->fish.dispatch (babl, (void*)src, (void*)dst, n, *babl->fish.data); src += source_stride; dst += dest_stride; diff --git a/babl/babl-fish.h b/babl/babl-fish.h index 36ef098..a73a358 100644 --- a/babl/babl-fish.h +++ b/babl/babl-fish.h @@ -32,7 +32,7 @@ typedef struct const Babl *source; const Babl *destination; void (*dispatch) (const Babl *babl, const char *src, char *dst, long n, void *data); - void *data; /* user data */ + void **data; /* user data - only used for conversion redirect */ double error; /* the amount of noise introduced by the fish */ /* instrumentation */ -- 2.30.2